<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class zap extends CI_Controller
{
	public function __construct()
	{
        parent::__construct();
		//$this->load->model(array('general_model'));
		$this->load->model('user_model');
		$this->template->set_template('template/admin_template');
		ini_set('memory_limit', '-1');
		if($this->general_model->loggedin("admin") == FALSE)
		{
			redirect(ADMIN_PATH);
		}
    }
	public function send_mail($to,$subject,$message)
	{
		$settingdata=$this->general_model->select_val("setting","*","id = 1");
		$this->load->library('email');
		$this->email->set_mailtype("html");
		$this->email->set_newline("\r\n");
		$this->email->from($settingdata['notification_email'],$settingdata['site_name']);
		$this->email->reply_to($settingdata['notification_email'], $settingdata['site_name']);	
		$this->email->to($to);		
		$this->email->subject($subject);		
		$this->email->message($message);
	   $this->email->send();
	}
	public function index()
	{
		$data['breadcrumb'] = set_crumbs(array(current_url() => 'Addmate'));
		$filter = process_filter('attorney');
		//print_r($filter);
		$search = array();

        if (isset($filter['search']))
        {
            $search['attorney_name'] = $filter['search'];
            
           // unset($filter['search']);
        }
		if (isset($filter['status']))
        {
           
            if($filter['status']=="paidattorney")
             $search['status'] = 1;
			 else 
			  $search['status'] = 0;
            //unset($filter['status']);
        }
		//print_r($filter);
		if ( ! empty($search))
        {
			if(isset($filter['search']) && isset($filter['status']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
				$this->db->where("status",$search['status']);
				$this->db->like("firstname",$search['attorney_name']);
				
				
				
				$count = $this->db->count_all_results();
			}
			else if(isset($filter['search']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
				
				$this->db->like("firstname",$search['attorney_name']);
				
				
				$count = $this->db->count_all_results();
			//$data['totalbusiness']  = $this->db->get()->result_array();
			}
			else if(isset($filter['status']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
				
				$this->db->where("status",$search['status']);
				
				
				$count = $this->db->count_all_results();
			}
			
        }
		else
		{
			$count=$this->general_model->count_row("attorney");
		}
		
		
		//$data['totalattorney'] = $this->general_model->select('attorney');
		//$count=count($data['totalattorney']);
		//echo $count;
		$perpage = 50;
		if ($count > $perpage) {
			$this->load->library('pagination');
		    $data['query_string'] = ( ! empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '';

			
			
			// Create Pagination
			$config['base_url'] = site_url(ADMIN_PATH . '/attorney/index/');
			$config['total_rows'] = $count;
			$config['per_page'] = $perpage; 
			$config['uri_segment'] = '4';
			$config['num_links'] = 4 ;
			$config['full_tag_open'] = false;
			$config['full_tag_close'] = false;
			$config['cur_tag_open'] = '<a href="#">';
			$config['cur_tag_close'] = '</a>';
			$config['next_tag_open'] = false;
			$config['next_tag_close'] = false;
			$config['prev_tag_open'] = false;
			$config['prev_tag_close'] = false;
			
			$config['num_tag_open'] = false;
			$config['num_tag_close'] = false;
			$config['suffix'] = $data['query_string'];
			$this->pagination->initialize($config); 
			$data['pagination'] = $this->pagination->create_links();
			$offset = $this->uri->segment(4);
	
		}
		else
		{
			$offset=0;
			$data['pagination']=0;
		}
		if ( ! empty($search))
        {
			if(isset($filter['search']) && isset($filter['status']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
				$this->db->order_by('userid','ASC');
				$this->db->where("status",$search['status']);
				$this->db->like("firstname",$search['attorney_name']);
				$this->db->limit($perpage,$offset);
			
				$data['attorney']  = $this->db->get()->result_array();
			}
			else if(isset($filter['search']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
			
				$this->db->order_by('userid','ASC');
				$this->db->like("firstname",$search['attorney_name']);
				$this->db->limit($perpage,$offset);
			
				$data['attorney']  = $this->db->get()->result_array();
			}
			else if(isset($filter['status']))
			{
				$this->db->select("*");
				$this->db->from("attorney");
			
				$this->db->order_by('userid','ASC');
				$this->db->where("status",$search['status']);
				$this->db->limit($perpage,$offset);
			
				$data['attorney']  = $this->db->get()->result_array();
			}
			
			
        }
		else{
		$data['attorney'] = $this->general_model->select_rows("attorney","*","attorneyid","asc",$perpage,$offset);
		}
		$this->template->content->view('admin/addmate/alladdmate', $data);
		$this->template->publish();
		
	}

	public function newsfeed()
	{
		$data['breadcrumb'] = set_crumbs(array(current_url() => 'News Feed Setting'));
		
		if($this->input->server('REQUEST_METHOD') === 'POST')
		{
			$this->general_model->truncate("zap_newsfeed");
			$newsfeeddata=$this->input->post('zap_newsfeed');
			
			if(!empty($newsfeeddata))
			{
				
				foreach ($newsfeeddata as $newsfeed)
				{
					$news_feed=array(
							"news_name"=>$newsfeed['news_name'],
							"news_url"=>$newsfeed['news_url'],
							"news_status"=>$newsfeed['news_status'],
							"date_added"=>date('Y-m-d')		
					);
					$this->general_model->insert("zap_newsfeed",$news_feed);
				}
			}
			$this->session->set_flashdata('message', '<p class="success">update successfully</p>');
			redirect(ADMIN_PATH . "/zap/newsfeed");
		}

		$data['allnewsfeed'] = $this->general_model->select('zap_newsfeed');
		$this->template->content->view('admin/zap/newsfeed', $data);
		$this->template->publish();
	}
	public function deleterestriction()
	{
		if ($this->input->post('selected'))
        {
            $selected = $this->input->post('selected');
        }
        else
        {
            $selected = (array) $this->uri->segment(5);
        }
		$this->general_model->delete_rows('restriction','id',$selected);
		
		$this->session->set_flashdata('message', '<p class="success">favorite Movie deleted Successfully.</p>');
		redirect(ADMIN_PATH . "/addmate/restriction");
	}
	
}


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */